package problema042;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Set;
import java.util.StringTokenizer;

public class triangleWords {
	
	static LinkedList <String> lista;
	static Set<Integer> conj = new HashSet<Integer>();
	
	public static void main(String[] args){
		System.out.println(cantTriangleWords());
	}
	
	public static int cantTriangleWords(){
		leer();
		generarConj();
		int res = 0;
		for(int i = 0; i < lista.size(); i++){
			if(esTW(lista.get(i))) res++;
		}		
		return res;
	}
	
	public static void generarConj(){
		double act = 0;
		for(int i = 1; i < 100; i++){
			act = ((0.5 * i) * (i+1));
			conj.add((int)act);
		}
	}
	
	public static boolean esTW(String s){
		int act = 0;
		for(int j = 0; j < s.length(); j++){
			act += s.charAt(j) - 64;
		}
		return conj.contains(act);
	}
	
	
	public static void leer(){
		lista = new LinkedList<String>();
		String word;
		try{
			BufferedReader reader = new BufferedReader( new FileReader("wordsEj42.txt") );
			String linea;
			while ((linea = reader.readLine()) != null){
				StringTokenizer st = new StringTokenizer(linea, "," );
				while (st.hasMoreTokens()){
					word = st.nextToken();
					lista.add(word.substring(1, word.length()-1));
				}
			}
			reader.close();
			}catch (Exception e){
				System.err.println("Error: " + e.getMessage());
			}
	}

}
